import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import {HttpServies} from '../../providers/http-servies';
import 'rxjs/add/operator/toPromise';
import {ContactPage} from "../contact/contact";
import {HomePage} from "../home/home";
/**
 * Generated class for the PersonalPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */


@Component({
  selector: 'page-personal',
  templateUrl: 'personal.html',
  providers:[HttpServies]
})
export class PersonalPage {
  dataJson:any=[];
    yhxxJson:any=[];
  userInfo = {
    'username': ''
  }
  constructor(public navCtrl: NavController, public navParams: NavParams,private http:HttpServies) {
  }

  ionViewDidLoad() {
    this.getInfo();
  }
  getInfo() {
    //个人信息
    this.http.httpPost('/Home/index/information')
        .then(res => {//成功
          if (res && res.code == 1) {
            console.log(res.msg);
            this.dataJson = res.data;
          } else {
            this.http.showErro(res.msg);
          }
        })
  }
  //修改昵称
  checkInfo(){
    var param = "newname=" + this.dataJson.username;
    this.http.httpPost('/Home/index/sett',param)
        .then(res => {//成功
          if (res && res.code == 1) {
            console.log(res.msg);
            this.http.showErro(res.msg);
              this.navCtrl.push(HomePage);
          }
        })
  }
  //退出登录
  tcInfo(){
    this.http.httpPost('/Home/index/loginout')
        .then(res => {//成功
          if (res && res.code == 1) {
              localStorage.clear();
              this.http.showErro("退出成功");
             this.navCtrl.push(ContactPage);
          }else{
              localStorage.clear();
              this.navCtrl.push(ContactPage);
              this.http.showErro("退出成功");
          }
        })
  }
}
